package com.zhangguo.springmvc01.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.Map;

/**
 * @author wangxing
 * @version 2020/6/1 5:37 Administrator
 */
@Controller
@RequestMapping("/request")
public class RequestController {
    private String url="foo/index";
    String msg="";
    String key="message";
    @RequestMapping(value="/action8",method ={RequestMethod.POST, RequestMethod.DELETE})
    public String action8(Model model){
        model.addAttribute(key,"@RequestMapping method 约束,收窄请求范围," +
                "本方法只能使用POST和DELETE进行访问");
        return url;
    }
    @RequestMapping(method = RequestMethod.GET)
    public String get(Model model){
        msg="hello from get 分类请求";
        model.addAttribute(key,msg);
        return url;
    }
    @RequestMapping(method = RequestMethod.POST)
    public String post(Model model){
        msg="hello from post 分类请求";
        model.addAttribute(key,msg);
        return url;
    }
    @RequestMapping(method = RequestMethod.PUT)
    public String put(Model model){
        msg="hello from put 分类请求";
        model.addAttribute(key,msg);
        return url;
    }
    @RequestMapping(method = RequestMethod.DELETE)
    public String delete(Model model){
        msg="hello from delete 分类请求";
        model.addAttribute(key,msg);
        return url;
    }
    @RequestMapping(method = RequestMethod.PATCH)
    public String path(Model model){
        msg="hello from patch 分类请求";
        model.addAttribute(key,msg);
        return url;
    }
    @RequestMapping(value = "/action9",consumes = "text/html")
    public String action9(Model model){
        msg="@RequestMapping,使用consumes指定处理提交内容的content-type," +
                "当前只处理content-type为text/html的相关数据";
        model.addAttribute(key,msg);
        return url;
    }
    private String action(Model model,String msg){
        model.addAttribute(key,msg);
        return url;
    }
    @RequestMapping(value = "action10",produces = "application/json")
    public String action10(Model model){
        String msg = "@RequestMapping,使用produces,指定客户端接收类型为application/json";
        return this.action(model,msg);
    }
    @RequestMapping(value = "action11",params={"id=123","name!=abc"})
    public String action11(Model model){
        msg="@RequestMapping,使用params指定请求中必须有的特定属性,收窄请求参数范围," +
                "请求中必须包含id=123,name不等于abc";
        return this.action(model,msg);
    }




}
